dd.project.ui.script({
    init:function()
    {
        dd.control("script", function(o)
        {
            o = o || {};
            o.x = o.x || 0;
            o.y = o.y || 0;
            o.text = "";
            o.height = o.height || 200;
            o.width = o.width || 300;
            o.font = "font" in o ? o.font : {size:14, family:"Consolas"};
            o._bo = {
                x: 0,
                y: navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ? 1 : 0
            };
            var control = dd(this.parent).group();
            dd(control).translate(o);
            var lineBack = dd(control).rect(0, 0, 34, o.height, {
                fill:"#333"
            });
            var lineText = dd(control).text("1\n2\n3\n4", {
                x: 28,
                y: 20,
                fill: "#FFF",
                textAnchor: "end",
                font:{size:o.font.size,family:o.font.family}
            });
            var codeBack = dd(control).rect(34, 0, o.width - 30, o.height, {
                fill:"#292929"
            });
            //var txt = dd(control).text(0, 0, 30, 0, {
            //});
            var inputWrap = dd(dd.body).addElement("div");
            var input = dd(inputWrap).addElement("pre", {
                contenteditable:"true"
            });
            dd(input).text = o.text;
            dd(input).css({
                display: "block",
                outline: "none",
                color: "#CCCA84",
                cursor: "text",
                padding: "6px",
                lineHeight: (o.font.size + 4) + "px",
                height: (o.height - 12) + "px",
                width: (o.width - 34) + "px",
                overflow: "auto",
                whiteSpace: "nowrap",
                fontSize: "14px",
                fontFamily: "Consolas"
            });
            dd(inputWrap).css({
                display: "block",
                position:"absolute",
                left: (o.x + o._bo.x + 34) + "px",
                top: (o.y + o._bo.y) + "px"
            });
            dd(input).event({
                keypress: function()
                {
                    // Should be using .text from svg module not core!
                    dd(this.lineText).text = dd(this).lines;
                    return true;
                },
                focus: function()
                {
                    
                },
                blur: function()
                {
                    
                }
            }, {lineText:lineText});
            this.property("x", {
                get:function()
                {
                    return dd(this.control).x;
                },
                set:function(v)
                {
                    dd(inputWrap).css({ left: v + "px"});
                    return dd(this.control).x = v;
                }
            }, {control:control, inputWrap:inputWrap});
            this.property("y", {
                get:function()
                {
                    return dd(this.control).y;
                },
                set:function(v)
                {
                    dd(inputWrap).css({ top: v + "px"});
                    return dd(this.control).y = v;
                }
            }, {control:control, inputWrap:inputWrap});
            this.method("load", function(o) {
                
            });
        });
    }
});